package com.mql.ganio;

import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.mql.ganio.ui.FragmentFactory;
import com.mql.ganio.ui.adapter.CommonFragmentPagerAdapter;
import com.mql.ganio.ui.base.BaseActivity;
import com.mql.ganio.ui.base.BaseFragment;
import com.mql.ganio.ui.base.BasePresenter;
import com.mql.ganio.util.UIUtils;
import com.mql.ganio.widget.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * @创建者 mql
 * @描述 主界面
 */
public class MainActivity extends BaseActivity {


    @Bind(R.id.vpContent)
    NoScrollViewPager mVpContent;

    @Bind(R.id.tvStudyNormal)
    TextView mTvStudyNormal;
    @Bind(R.id.tvStudyPress)
    TextView mTvStudyPress;
    @Bind(R.id.tvStudyTextNormal)
    TextView mTvStudyTextNormal;
    @Bind(R.id.tvStudyTextPress)
    TextView mTvStudyTextPress;


    @Bind(R.id.tvAskNormal)
    TextView mTvAskNormal;
    @Bind(R.id.tvAskPress)
    TextView mTvAskPress;
    @Bind(R.id.tvAskTextNormal)
    TextView mTvAskTextNormal;
    @Bind(R.id.tvAskTextPress)
    TextView mTvAskTextPress;


    @Bind(R.id.tvFindNormal)
    TextView mTvFindNormal;
    @Bind(R.id.tvFindPress)
    TextView mTvFindPress;
    @Bind(R.id.tvFindTextNormal)
    TextView mTvFindTextNormal;
    @Bind(R.id.tvFindTextPress)
    TextView mTvFindTextPress;


    private List<BaseFragment> mFragmentList = new ArrayList<>();

    @Override
    public void initView() {
        //默认选中第一个
        setTransparency();
        mTvStudyPress.getBackground().setAlpha(255);
        mTvStudyTextPress.setTextColor(UIUtils.getColor(R.color.colorPrimary));

        //设置ViewPager的最大缓存页面
        mVpContent.setOffscreenPageLimit(3);
        mFragmentList.add(FragmentFactory.getInstance().getGanIoFragment());
        mFragmentList.add(FragmentFactory.getInstance().getAskFragment());
        mFragmentList.add(FragmentFactory.getInstance().getFindFragment());
        mVpContent.setAdapter(new CommonFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList));
    }


    @Override
    public void initListener() {
    }

    @Override
    public void initData() {
        mVpContent.setCurrentItem(0, false);
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected boolean isToolbarCanBack() {
        return false;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_main;
    }

    /**
     * 把press图片、文字全部隐藏(设置透明度)
     */
    private void setTransparency() {
        mTvStudyNormal.getBackground().setAlpha(255);
        mTvAskNormal.getBackground().setAlpha(255);
        mTvFindNormal.getBackground().setAlpha(255);

        mTvStudyPress.getBackground().setAlpha(1);
        mTvAskPress.getBackground().setAlpha(1);
        mTvFindPress.getBackground().setAlpha(1);

        mTvStudyTextNormal.setTextColor(UIUtils.getColor(R.color.white));
        mTvAskTextNormal.setTextColor(UIUtils.getColor(R.color.white));
        mTvFindTextNormal.setTextColor(UIUtils.getColor(R.color.white));

        mTvStudyTextPress.setTextColor(Color.argb(0, 69, 192, 26));
        mTvAskTextPress.setTextColor(Color.argb(0, 69, 192, 26));
        mTvFindTextPress.setTextColor(Color.argb(0, 69, 192, 26));

    }


    @OnClick({R.id.llStudy, R.id.llAsk, R.id.llFind})
    public void onClick(View view) {
        setTransparency();
        switch (view.getId()) {
            case R.id.llStudy:
                mVpContent.setCurrentItem(0, false);
                mTvStudyPress.getBackground().setAlpha(255);
                mTvStudyTextPress.setTextColor(UIUtils.getColor(R.color.colorPrimary));
                break;
            case R.id.llAsk:
                mVpContent.setCurrentItem(1, false);
                mTvAskPress.getBackground().setAlpha(255);
                mTvAskTextPress.setTextColor(UIUtils.getColor(R.color.colorPrimary));
                break;
            case R.id.llFind:
                mVpContent.setCurrentItem(2, false);
                mTvFindPress.getBackground().setAlpha(255);
                mTvFindTextPress.setTextColor(UIUtils.getColor(R.color.colorPrimary));
                break;
        }
    }


}
